package cn.java.threadmodel;

import java.util.concurrent.Exchanger;

/**
 * @author 小石潭记
 * @date 2021/12/18 20:54
 * @Description: ${todo}
 */
public class ThreadA extends Thread {
    private Exchanger<String> exchanger;

    public ThreadA(Exchanger<String> exchanger) {
        this.exchanger = exchanger;
    }

    @Override
    public void run() {
        try {
            String exchange = exchanger.exchange("中国人A");
            System.out.println("在线程A中得到线程B的值=" + exchange);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
